var express = require("express");
var router = express.Router();
const formidable = require("formidable");
const mysql = require("mysql");
const pool = mysql.createPool({
  host: "localhost",
  user: "root",
  password: "123456",
  database: "nodedatabase",
  port: 3306,
});
const logger = require("../logger");
/* GET users listing. */
// 增加用户
router.post("/", function (req, res, next) {
  var form = new formidable.IncomingForm();
  form.parse(req, function (err, fields, files) {
    res.send(fields);
  });
  // res.send(res);
});

router.get("/", function (req, res, next) {
  pool.getConnection(function (err, connection) {
    if (err) {
      logger.error(err);
      return;
    }
    connection.query("SELECT * FROM t_user WHERE name='linchang'", [], (err, result) => {
      if (err) {
        logger.error(err);
      } else {
        res.status(200).send(result);
        connection.release();
      }
    });
  });
});

module.exports = router;
